#include "WrapCodeGeneratorOsg.h"
// #include <QtCore/QFile>
#include <iostream>
#include <fstream>


WrapCodeGeneratorOsg::WrapCodeGeneratorOsg()
{
}

WrapCodeGeneratorOsg::~WrapCodeGeneratorOsg()
{
}

void WrapCodeGeneratorOsg::genInclude_h(CppInfo::ClassPtr classPtr, EString& content)
{
    
    content += EString("#include <DefineCommon.h>\n");
    content += EString("#include <ItemBaseOsg.h>\n");

    EString name = classPtr->userData["origClassName"];
    name.replace("::", "/");
    content += EString("#include <") + name + ">\n";
    content += "\n";
}
void WrapCodeGeneratorOsg::genClassDecl_h(CppInfo::ClassPtr classPtr, EString& content)
{
    EString name = classPtr->name;

    content += EString("class ") + name + ";\n";
    content += EString("typedef SmartPtr(") + name + ") " + name + "Ptr;\n";
    content += EString("class ") + name + ": public ItemBaseOsg\n";

    content += EString("{") + "\n";
    content += EString("public:") + "\n";
}

void WrapCodeGeneratorOsg::genClassVariablesOrignalPtr_h(CppInfo::ClassPtr classPtr, EString& content)
{
    EString name = classPtr->userData["origClassName"];
    content += EString("    osg::ref_ptr<")+name+"> m_origPtr;\n";
    // for(int i = 0 ; i < classPtr->variableList.size(); i++)
    // {
        // CppInfo::VariablePtr var = classPtr->variableList[i];
        // content += EString("    ") + var->typeName + " " + var->name+ ";\n";
    // }
    content += "\n";
}

void WrapCodeGeneratorOsg::genClassFunGetOrigPtr_h(CppInfo::ClassPtr classPtr, EString& content)
{
    EString name = classPtr->userData["origClassName"];
    content += EString("    virtual intptr_t getOrigPtr()\n");
    content += EString("    {\n");
    content += EString("        return (intptr_t)(this->m_origPtr.get());\n");
    content += EString("    }\n");
}

void WrapCodeGeneratorOsg::genClassConstructor_h(CppInfo::ClassPtr classPtr, EString& content)
{
    EString name = classPtr->name;
    EString origClassName = classPtr->userData["origClassName"];

    content += EString("    ") + name + "()\n";
    content += EString("    {\n");
    content += EString("        m_origPtr = new ")+origClassName+";\n";
    content += EString("        this->fillPropertys();\n");
    content += EString("    }\n");
    content += EString("\n");

}

void WrapCodeGeneratorOsg::genClassDestructor_h(CppInfo::ClassPtr classPtr, EString& content)
{
    EString name = classPtr->name;
    content += EString("    ~") + name + "()\n";
    content += EString("    {\n");
    content += EString("    }\n");
    content += "\n";
}

bool WrapCodeGeneratorOsg::ifSupportVariableType(const EString& varType)
{
    bool result = false;
    EStringList supportTypeList;
    supportTypeList.push_back("int");
    supportTypeList.push_back("unsigned int");
    supportTypeList.push_back("std::string");
    supportTypeList.push_back("const std::string &");
    supportTypeList.push_back("double");
    supportTypeList.push_back("osg::Vec2");
    supportTypeList.push_back("osg::Vec3");
    supportTypeList.push_back("osg::Vec4");
    supportTypeList.push_back("osg::Matrix");
    supportTypeList.push_back("const osg::Matrix &");
    supportTypeList.push_back("bool");
    // if(supportTypeList.contains(varType))
    if(EString::EStringListContains(supportTypeList, varType))
    {
        result = true;
    }

    return result;
}

EString WrapCodeGeneratorOsg::unifyVariableType(const EString& varType)
{
    EString result = varType;
    if(varType == "const std::string &")
    {
        result = "std::string";
    }
    else if(varType == "const osg::Matrix &")
    {
        result = "osg::Matrix";
    }
    return result;
}
